{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.5 64-bit ('base': conda)",
   "metadata": {
    "interpreter": {
     "hash": "aa9e82663741a35949d10b71616b7da32b0b1a8a92bded1e278bf973221dadc2"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow.keras import layers, metrics\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(2, 3, 3, 4), dtype=float32, numpy=\n",
       "array([[[[  9.11372   ,   2.043083  ,   6.522096  ,   5.5589814 ],\n",
       "         [  3.0917156 ,  -0.94055265,  10.000361  ,   3.8168907 ],\n",
       "         [ -0.5629463 ,   0.35067976,  -2.6255064 ,  -9.762131  ]],\n",
       "\n",
       "        [[  2.3058367 , -11.030293  ,   7.872267  , -11.571086  ],\n",
       "         [  2.0472414 ,   5.372498  ,  -1.9700241 ,  -2.258205  ],\n",
       "         [  2.7118654 ,  -5.3573112 ,  -7.8718286 , -12.085476  ]],\n",
       "\n",
       "        [[  5.2728214 , -11.932029  ,  12.852921  ,   6.7414546 ],\n",
       "         [ -6.9092216 ,  -7.389769  ,   5.489472  ,  -5.000499  ],\n",
       "         [  2.8725777 ,   3.6713774 ,   0.7149567 ,   0.65462303]]],\n",
       "\n",
       "\n",
       "       [[[ -1.115265  ,   4.1083555 ,  -2.5255313 ,   9.202957  ],\n",
       "         [  0.29818594,  -2.5868776 ,   4.678013  ,  -0.68337345],\n",
       "         [ -0.09973422,  -1.1905187 ,  -6.3024316 ,  -2.7789085 ]],\n",
       "\n",
       "        [[  7.266691  ,  -0.09233466,  -8.892083  ,   3.117109  ],\n",
       "         [  4.029881  , -15.32508   ,  14.716504  ,   7.3150105 ],\n",
       "         [ -0.07037057,   3.0438137 ,   0.108697  ,   2.368587  ]],\n",
       "\n",
       "        [[ -2.3177714 ,   6.579771  ,  -2.330303  ,  -4.138298  ],\n",
       "         [ -6.4585595 ,   2.655114  ,   1.1147835 ,   7.364477  ],\n",
       "         [ -0.8641875 ,   3.955882  ,  -0.29783782,  -0.46171594]]]],\n",
       "      dtype=float32)>"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "x = tf.random.normal([2, 5, 5, 3])\n",
    "w = tf.random.normal([3, 3, 3, 4])\n",
    "out = tf.nn.conv2d(x, w, strides=1, padding=[[0, 0], [0, 0], [0, 0], [0, 0]])\n",
    "out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[<tf.Variable 'conv2d_1/kernel:0' shape=(3, 3, 3, 4) dtype=float32, numpy=\n",
       " array([[[[-0.05170229,  0.05187529,  0.03159937, -0.01262054],\n",
       "          [ 0.27058282, -0.14017566, -0.10022399,  0.12346765],\n",
       "          [-0.06603323, -0.08148091,  0.25977477, -0.23338225]],\n",
       " \n",
       "         [[ 0.19082874, -0.18771744, -0.29443473, -0.17361946],\n",
       "          [-0.23446119, -0.16180216,  0.10601491,  0.10706168],\n",
       "          [-0.22206941, -0.2168883 ,  0.02244586,  0.09699136]],\n",
       " \n",
       "         [[ 0.13538942,  0.09766379,  0.06453806, -0.02184334],\n",
       "          [-0.26647133,  0.17954636,  0.02667004, -0.2541209 ],\n",
       "          [-0.21577558, -0.18392244,  0.17734072,  0.25134018]]],\n",
       " \n",
       " \n",
       "        [[[ 0.2866411 , -0.18963398, -0.03211132,  0.21291187],\n",
       "          [-0.05368346,  0.04127878,  0.29373887,  0.29490504],\n",
       "          [-0.27375907, -0.0961659 , -0.03935811,  0.2113631 ]],\n",
       " \n",
       "         [[ 0.20012304,  0.09352702,  0.27466163,  0.29322246],\n",
       "          [ 0.25178644, -0.04568872,  0.14271459, -0.01548028],\n",
       "          [-0.26594606,  0.03429407,  0.1316235 , -0.206568  ]],\n",
       " \n",
       "         [[ 0.05715904,  0.06677231, -0.15297823,  0.10810629],\n",
       "          [-0.19781655, -0.28133658, -0.2738826 , -0.02867922],\n",
       "          [ 0.1340253 ,  0.14317432, -0.22947595, -0.2621748 ]]],\n",
       " \n",
       " \n",
       "        [[[ 0.2757121 ,  0.02216613,  0.1048972 ,  0.01566252],\n",
       "          [ 0.03499144, -0.00527126, -0.20702817, -0.09573252],\n",
       "          [ 0.12475562,  0.2822018 , -0.00262532, -0.03648573]],\n",
       " \n",
       "         [[-0.04790157, -0.15213215, -0.18096434,  0.24100253],\n",
       "          [ 0.156277  ,  0.15513831, -0.11225149, -0.09300183],\n",
       "          [ 0.1540707 ,  0.30299166, -0.30155724,  0.26016906]],\n",
       " \n",
       "         [[ 0.20306614,  0.0990839 ,  0.245976  , -0.18188016],\n",
       "          [ 0.0242241 , -0.2323259 , -0.0379591 ,  0.06740743],\n",
       "          [-0.00751889,  0.07016984, -0.21400648, -0.12516907]]]],\n",
       "       dtype=float32)>,\n",
       " <tf.Variable 'conv2d_1/bias:0' shape=(4,) dtype=float32, numpy=array([0., 0., 0., 0.], dtype=float32)>]"
      ]
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "x = tf.random.normal([2, 5, 5, 3])\n",
    "layer = layers.Conv2D(4, kernel_size=3, strides=1, padding='SAME')\n",
    "out = layer(x)\n",
    "out\n",
    "layer.trainable_variables"
   ]
  }
 ]
}